﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;
using System.Text;

namespace WuxiWTO.Web
{
    public partial class userCenter : System.Web.UI.Page
    {
        WTODataContext contex = new WTODataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_name"] == null && Request.Cookies["wtouser"] == null)
            {
                Response.Redirect(Server.HtmlEncode("login.aspx?ret=userCenter.aspx"));
            }
            if (!IsPostBack)
            {
                InitRegValidate();
            }
        }

        private void InitRegValidate()
        {
            if (UserInfo.AllowRegValidate())
            {
                this.panAllowRegValidate.Visible = true;
            }
            else
            {
                this.panAllowRegValidate.Visible = false;
            }
        }

        protected void Page_PreRender(object sender,EventArgs e)
        {
            
            GetUserInfo();
        }

        private void GetUserInfo()
        {
            supporter user = contex.supporters.SingleOrDefault(p => p.supporter_login_name == Session["user_name"].ToString());
            if (user != null)
            {
                if (user.is_active == 'F')
                {
                    litValidateStatus.Text = "注册信息审核未通过,原因：" + user.validate_reason;
                    litValidateStatus.ForeColor = System.Drawing.Color.Red;
                    this.hyInfo.Visible = true;
                }
                else if (user.is_active == 'Y')
                {
                    litValidateStatus.Text = "已经通过审核";
                    litValidateStatus.ForeColor = System.Drawing.Color.Green;
                    this.hyInfo.Visible = false;
                }
                else if (user.is_active == 'N')
                {
                    litValidateStatus.Text = "您的注册信息尚未审核，请等待";
                    litValidateStatus.ForeColor = System.Drawing.Color.Red;
                    this.hyInfo.Visible = false;
                }
                if (user.supporter_type == 'I')
                {
                    panIndividual.Visible = true;
                    panCompany.Visible = false;
                    this.lblEmailI.Text = user.email;
                    this.lblIdentity.Text = user.identity_card;
                    this.lblLoginNameI.Text = user.supporter_login_name;
                    this.lblNameI.Text = user.supporter_name;
                    this.lblPasswordI.Text = user.supporter_password.First().ToString() + "******";
                    this.lblTelephoneI.Text = user.telephone;
                }
                else
                {
                    panIndividual.Visible = false;
                    panCompany.Visible = true;
                    this.lblEmailO.Text = user.email;
                    this.lblEnterpriseName.Text = user.enterprise_name;
                 
                    this.lblLoginNameO.Text = user.supporter_login_name;
                    this.lblPasswordO.Text = user.supporter_password.First().ToString() + "******";
                    this.lblTelephoneO.Text = user.telephone;
                    this.lblContact.Text = user.contact;
                    this.lblPosition.Text = user.position;
                    this.lblTelephoneO.Text = user.mobile;
                    this.lblAddress.Text = user.enterprise_address;
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "fa", "alert('参数传递失败');", true);
                return;
            }
        }
        private string GetPurposeByCode(string code)
        {
            string purpose = "";
            switch (code)
            {
                case "2": purpose = "外商投诉"; break;
                case "3": purpose = "培训报名"; break;
                case "4": purpose = "其他原因"; break;
                default: break;
            }
            return purpose;
        }
    }
}